﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace XGameFrame.Graphic
{
    public class StaticSpriteManager:List<StaticSpriteBase>
    {
        public StaticSpriteManager()
        {

        }

        public void Update(GameTime pGameTime, PlayerIndex pPlayerIndex)
        {
            if (Count == 0)
                return;
            foreach (StaticSpriteBase sprite in this)
            {
                sprite.IsHover = CheckMouseOverSprite(sprite);
                if (sprite.Enabled)
                    sprite.Update(pGameTime);
                if (sprite.Enabled)
                    sprite.HandleInput(pPlayerIndex);
                if (sprite.IsHover)
                    sprite.OnHover(pPlayerIndex);
            }
        }

        public void Draw(SpriteBatch pSpriteBatch)
        {
            foreach (StaticSpriteBase sprite in this)
            {
                if (sprite.Visible)
                    sprite.Draw(pSpriteBatch);
            }
        }

        private Boolean CheckMouseOverSprite(StaticSpriteBase pSprite)
        {
            return pSprite.Bounds.Intersects(new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1));
        }

    }
}
